<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2008 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: register.php
| Author: Nick Jones (Digitanium)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "maincore.php";
require_once THEMES."templates/header.php";
include LOCALE.LOCALESET."register.php";
include LOCALE.LOCALESET."user_fields.php";

//Oppkobling mot databasen. Opkoblingsinfo ligger i config.php
$avloserid_fra_visning=$_GET['avloserid'];
$db = mysql_connect($GLOBALS['db_host'], $GLOBALS['db_user'], $GLOBALS['db_password']);
mysql_select_db($GLOBALS['db_name'], $db); 

$query="SELECT aktiv FROM aktiv";
$result=mysql_query($query);

$options="";

while ($row=mysql_fetch_array($result)) {
    $aktiv=$row['aktiv'];
    $options.="<OPTION VALUE=\"$aktiv\">".$aktiv;
}

//--------------------------------------------------------------------------------------------
//Her begynner koden for å hente ut persondata
//Lagrer spørringen som en string i variablen $query
$query=" SELECT * FROM avloser, postkatalog 
		 WHERE avloserid=".$avloserid_fra_visning." 
		 AND avloser.postnr = postkatalog.postnr"; 	
//Henter ut all info fra avloser og postkat tabellene og lagrer info fra DB i variablen $result
$result=mysql_query($query);
//Teller antall rader i variablen $result og lagrer antallet i variablen $num					
$num=mysql_numrows($result);					

// Setter telleren $i til 0
$i=0;

//While løkken går gjennom gjennom variablen result så lenge telleren $i er mindre en antall rader $num											
while ($i < $num) {
	$fornavn/*Variablen data skal lagres i*/=mysql_result($result/*Variablen data skal hentes ut fra*/,$i/*Nummer på raden data skal hentes fra*/,"fornavn"/*navn på felt i DB*/);
	$etternavn=mysql_result($result,$i,"etternavn");
	$adresse=mysql_result($result,$i,"adresse");
	$postnr=mysql_result($result,$i,"postnr");
	$telefon=mysql_result($result,$i,"telefon");
	$mobil=mysql_result($result,$i,"mobil");
	$epost=mysql_result($result,$i,"epost");
	$aktiv=mysql_result($result,$i,"aktiv");
	$poststed=mysql_result($result,$i,"poststed");
	++$i; //teller økes med 1
}
//Skriver ut tabellen som persondata skal stå i 
echo "
	/n 
	<form action='lagre_profil.php' method='post' >
	<input type='hidden' name='ud_avloserid' value=$avloserid_fra_visning>
	<table class='capmain' border='0' cellpadding='0' align='center' width='608px'>
	
		<tr>
			<th><font style='text-transform: capitalize;'>Informasjon om:&nbsp; $fornavn  $etternavn </font></th>
		</tr>
	</table>
	
		<table class='imagetable' border='0' cellpadding='5' tableborder='10' align='center'>
		<tr>	<th><b>Fornavn</b></th>		<td><input type='text' name='ud_fornavn' value='$fornavn'></td>		</tr>
		<tr>	<th><b>Etternavn</b></th>	<td><input type='text' name='ud_etternavn' value='$etternavn'></td>	</tr>
		<tr>	<th><b>Adresse</b></th>		<td><input type='text' name='ud_adresse' value='$adresse'></td>		</tr>
		<tr>	<th><b>Postnr</b></th>		<td><input type='text' name='ud_postnr' value='$postnr'></td>		</tr>
		<tr>	<th><b>Poststed</b></th>	<td><input type='text' name='ud_poststed' value='$poststed' readonly='readonly' style='background-color: #D4D4D4' ></td>	</tr>
		<tr>	<th><b>Telefon</b></th>		<td><input type='text' name='ud_telefon' value='$telefon'></td>		</tr>
		<tr>	<th><b>Mobil</b></th>		<td><input type='text' name='ud_mobil' value='$mobil'></td>			</tr>
		<tr>	<th><b>Epost</b></th>		<td><input type='text' name='ud_epost' value='$epost'></td>			</tr>
		<tr>	<th><b>Aktiv</b></th>		<td><SELECT NAME='ud_aktiv'><OPTION VALUE=0>$options</SELECT></td>	</tr>
		<tr>	<th><b>Type</b></th>		<td><b>Administrasjon:</b><input type='checkbox' name='type[]' value='Administrasjon'><b>Avl&oslash;ser:</b><input type='checkbox' name='type[]' value='Avl&oslash;ser'><b>Annen n&aelig;ring:</b><input type='checkbox' name='type[]' value='Annen n&aelig;ring'><b>Utenlandsk arb.kraft:</b><input type='checkbox' name='type[]' value='Utenlandsk arb.kraft'></td>	</tr>
	
	</table>
	<table class='imagetable' border='0' cellpadding='5' tableborder='10' align='center'>
		<tr>
	</td>
	<td align=center><input type='Submit' value='Oppdater info'></form></td>
	<td align=center><form action='avloser_delete.php?avloserid=$avloserid_fra_visning' method='post'><input type='Submit' value='Slett person'></form></td>
		</tr>
	</table></form>";
//Her slutter koden for å hente ut persondata		

require_once THEMES."templates/footer.php";
?>